
    <div class="visible-phone">
      <a href="#top_10">Top ten</a>
    </div>
<div class='row'>

    <div id= 'left-side' class="span6">
    <?php
    if($this->ion_auth->logged_in())  
    {
    ?>

      <?php if(!tour_started()) { ?>
      <div class='panel'>
      <div class='buttons' style="margin-bottom: 20px;"><?php echo anchor('selection/edit', '<i class="icon-edit icon-white"></i> '.lang('edit_selection'), 'class="btn btn-primary"'); ?></div>
      <p><?php echo lang('selection_intro_pre'); ?></p>
      </div>
      <?php
      }
      ?>
      
      <!-- user <?php echo $user->username;?> stage scores -->
      <div class='panel'>
        <h2>Team: <?php echo $user->username;?></h2>
        <?php if($last_stage) { ?>
        <h3><?php echo sprintf(lang('your_scores_stage'), $last_stage->stage_id);?></h3>
        <?php } ?>
        <?php
        if(is_object($user_points))
        {
          if ($user_points->points_total > 0)
          {
          ?>
            <p><?php echo sprintf(lang('your_scores_stage_text'), $user_points->points_total);?></p>
          <?php
          }
          else
          {
          ?>
            <p><?php echo lang('no_score_stage_text');?></p>
          <?php
          }
        } ?>
      <?php if($last_stage) {
      foreach ($last_stage->result_riders as $res_rider)
      {
        if(is_object($res_rider))
        {
          $all_stage_points =  explode(',',$res_rider->points_stage);
          $result_riders[$res_rider->rider_id]  = $all_stage_points[$last_stage->stage_id];
        }
        else
        {
          $result_riders[0] = 0;
        }
      }
      foreach ($last_stage->yellow_riders as $res_rider)
      {
        if(is_object($res_rider))
        {
          $all_yellow_points =  explode(',',$res_rider->points_stage_yellow);
          $yellow_riders[$res_rider->rider_id]  = $all_yellow_points[$last_stage->stage_id];
        }
        else
        {
          $yellow_riders[0] = 0;
        }
      }
      foreach ($last_stage->green_riders as $res_rider)
      {
        if(is_object($res_rider))
        {
          $all_green_points =  explode(',',$res_rider->points_stage_green);
          $green_riders[$res_rider->rider_id]  = $all_green_points[$last_stage->stage_id];
        }
        else
        {
          $green_riders[0] = 0;
        }
      }
      foreach ($last_stage->mountain_riders as $res_rider)
      {
        if(is_object($res_rider))
        {
          $all_mountain_points =  explode(',',$res_rider->points_stage_mountain);
          $mountain_riders[$res_rider->rider_id]  = $all_mountain_points[$last_stage->stage_id];
        }
        else
        {
          $mountain_riders[0] = 0;
        }
      }
      }      
      ?>
      <?php
        if(is_object($user_points))
        {
          if ($user_points->points_total > 0)
          {
          ?>
          <table class='table table-condensed'>
            <thead>
              <th colspan='2'><?php echo lang('rider');?></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('stage_results');?>"><img src="<?php echo base_url();?>assets/images/jersey_stage.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('overall_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_yellow.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('points_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_green.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('mountain_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_mountain.gif" /></a></th>
              <th class='centertext'><?php echo lang('total');?></th>
            </thead>
            <tbody>
              <?php
              $total_stage_user = 0;
              foreach($selection_rider_ids as $key => $value)
              {
                if(array_key_exists($value, $result_riders) ||
                   array_key_exists($value, $green_riders) ||
                   array_key_exists($value, $yellow_riders) ||
                   array_key_exists($value, $mountain_riders))
                {
                  $sel_rider = $this->riders_model->get_by_id($value);
                ?>
                <tr>
                  <?php $rider_total =0;?>
                  <td><?php echo $sel_rider->number;?></td>
                  <td><?php echo anchor('info/rider/'.$sel_rider->rider_id,$sel_rider->last_name." ".$sel_rider->first_name)." (".anchor('info/team/'.$sel_rider->team_number, $sel_rider->team_shortname).")";?></td>
                  <td class='centertext'><?php if (isset($result_riders[$value]))   { echo $result_riders[$value]; $rider_total   =  $result_riders[$value]; }                  else { echo '-';}?></td>
                  <td class='centertext'><?php if (isset($yellow_riders[$value]))   { echo $yellow_riders[$value]; $rider_total   =  $rider_total + $yellow_riders[$value]; }   else { echo '-';}?></td>
                  <td class='centertext'><?php if (isset($green_riders[$value]))    { echo $green_riders[$value]; $rider_total    =  $rider_total + $green_riders[$value]; }    else { echo '-';}?></td>
                  <td class='centertext'><?php if (isset($mountain_riders[$value])) { echo $mountain_riders[$value]; $rider_total =  $rider_total + $mountain_riders[$value]; } else { echo '-';}?></td>
                  <td class='centertext'><?php echo $rider_total; $total_stage_user = $total_stage_user + $rider_total?></td>
                </tr>
               <?php
                }
              }
              ?>
            </tbody>
            <tfoot>
              <td colspan='6' class='righttext'><?php echo lang('total')." ".lang('stage')." ".$last_stage->stage_id.": ";?></td>
              <td class='centertext'><?php echo $total_stage_user;?></td>
          </table>
          <?php 
          }
        }
        ?>
        <!-- end user <?php echo $user->username;?> stage scores -->
        <!-- user <?php echo $user->username;?> total scores -->
        <?php if($last_stage) { ?>
        <h3>Jouw totaal aantal punten na etappe <?php echo $last_stage->stage_id;?></h3>
        <?php } ?>
        <table class='table table-condensed'>
          <thead>
            <tr>
              <th><?php echo lang('rider');?></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('stage_results');?>"><img src="<?php echo base_url();?>assets/images/jersey_stage.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('overall_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_yellow.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('points_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_green.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('mountain_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_mountain.gif" /></a></th>
              <th class='centertext'><?php echo lang('total');?></th>
            </tr>
          </thead>
          <tbody>

            <?php $total_points = 0;?>
        <?php foreach($selection as $rider)
        {
        ?>
          
        <?php    
          if (isset($rider) && is_object($rider))
          {
            $class="rider";
            if (!$rider->active)
            {
              $class .= " inactive";
            }
        ?>   
              <tr class="<?php echo $class;?>">
                <td><?php echo $rider->number." ".
                anchor('info/rider/'.$rider->rider_id,$rider->last_name." ".$rider->first_name)." (".anchor('info/team/'.$rider->team_number, $rider->team_shortname).")"; ?></td>
                <td class='centertext'>
                  <?php
                  if(array_sum(explode(',',$rider->points_stage)) > 0 )
                  {
                    echo array_sum(explode(',',$rider->points_stage));
                  }
                  else
                  {
                    echo "-";
                  }?>
                </td>
                <td class='centertext'>
                 <?php
                  if(array_sum(explode(',',$rider->points_stage_yellow)) > 0 )
                  {
                    echo array_sum(explode(',',$rider->points_stage_yellow));
                  }
                  else
                  {
                    echo "-";
                  }?>
                </td>
                <td class='centertext'>
                 <?php
                  if(array_sum(explode(',',$rider->points_stage_green)) > 0 )
                  {
                    echo array_sum(explode(',',$rider->points_stage_green));
                  }
                  else
                  {
                    echo "-";
                  }?>
                </td>                
                <td class='centertext'>
                 <?php
                  if(array_sum(explode(',',$rider->points_stage_mountain)) > 0 )
                  {
                    echo array_sum(explode(',',$rider->points_stage_mountain));
                  }
                  else
                  {
                    echo "-";
                  }?>
                </td>
                <td class='centertext'>
                  <?php
                  if (array_sum(explode(',',$rider->points_stage)) + array_sum(explode(',',$rider->points_stage_yellow)) + array_sum(explode(',',$rider->points_stage_green)) + array_sum(explode(',',$rider->points_stage_mountain))>0)
                  {
                    echo array_sum(explode(',',$rider->points_stage)) + array_sum(explode(',',$rider->points_stage_yellow)) + array_sum(explode(',',$rider->points_stage_green)) + array_sum(explode(',',$rider->points_stage_mountain));
                  }
                  else
                  {
                    echo "-";
                  }                    
                  $total_points = $total_points + array_sum(explode(',',$rider->points_stage)) + array_sum(explode(',',$rider->points_stage_yellow)) + array_sum(explode(',',$rider->points_stage_green)) + array_sum(explode(',',$rider->points_stage_mountain));?>
                </td>                  
              </tr>
         <?php
          }
          else
          {
            echo lang('no_selection_yet');
          }
        } ?>
         </tbody>
           <tfoot>
            <tr>
                <td colspan='5' class='righttext'><?php echo lang('total').": ";?></td>
                <td class='centered'><?php echo $total_points;?></td>
            </tr>
          </tfoot>
        </table>
        <!-- end user <?php echo $user->username;?> total scores -->
      </div>
      <?php
      }
      else
      {
      ?>
      <!-- login panel -->
      <div class='panel'>
        <h3><?php echo lang('login');?></h3>
        <?php echo form_open("auth/login", 'class="form-inline"');?>
        <?php echo form_input($identity);?>
        <?php echo form_input($password);?><br/><br/>
        
        <label for="remember">
        <?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?>&nbsp;<?php echo lang('remember_me');?></label>
        <button type="submit" class="btn"><?php echo lang('login');?></button><br/><br/>
        <?php echo anchor("auth/forgot_password",lang('forgot_password'));?><br/><br/>
        <?php echo anchor('account/register', lang('no_account_yet'), 'class="btn btn-large btn-primary"');?>
        <?php echo form_close();?>
      </div>
      <?php 
      }
      ?>
      <!-- end login panel -->
    </div>
    <!-- end #left-side -->

    <div id='right-side' class='span6'>
      
      <div class='panel'>
        <!-- top scorers last stage -->
        <?php if($last_stage)
        {
        ?>
        <h2><?php echo lang('last_stage').": #".$last_stage->stage_id."</h2><h3>".$last_stage->stage_depart." - ".$last_stage->stage_arrive." (".lang($last_stage->stage_type)." - ".$last_stage->stage_distance."km)";?></h3>
        <h3><?php echo sprintf(lang('top_scorers_stage'), $last_stage->stage_id);?></h3>
        <p><?php echo sprintf(lang('top_scorers_stage_text'), anchor('info/user_teams/'.$top_10_last_stage[0]->id,$top_10_last_stage[0]->username)); ?></p>
      
        <table class='table table-condensed'>
          <thead>
            <tr>
              <th><?php echo lang('user_team');?></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('stage_results');?>"><img src="<?php echo base_url();?>assets/images/jersey_stage.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('overall_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_yellow.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('points_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_green.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('mountain_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_mountain.gif" /></a></th>
              <th class='centertext'><?php echo lang('total');?></th>
          </thead>
          <tbody>
            <?php foreach($top_10_last_stage as $user_top_day)
            {
            ?>
            <tr>
              <td><?php echo $user_top_day->username;?></td>
              <td class='centertext'>
                <?php
                if ($user_top_day->points_stage > 0)
                {
                  echo $user_top_day->points_stage;
                }
                else
                {
                  echo "-";
                }
                ?>
              </td>
              <td class='centertext'><?php if ($user_top_day->points_yellow > 0)
                {
                  echo $user_top_day->points_yellow;
                }
                else
                {
                  echo "-";
                }                
                ?>
              </td>
              <td class='centertext'><?php if ($user_top_day->points_green > 0)
                {
                  echo $user_top_day->points_green;
                }
                else
                {
                  echo "-";
                }                
                ?>
              </td>
              <td class='centertext'><?php if ($user_top_day->points_mountain > 0)
                {
                  echo $user_top_day->points_mountain;
                }
                else
                {
                  echo "-";
                }                
                ?>
              </td>
              <td class='centertext'><?php echo $user_top_day->points_stage + $user_top_day->points_yellow + $user_top_day->points_green + $user_top_day->points_mountain;?></td>
            </tr>          
            <?php  
            }
            ?>
          </tbody>
        </table>
        <?php echo anchor('ranking/stage/'.$last_stage->stage_id, sprintf(lang('see_all_rankings_for_stage'),$last_stage->stage_id).' <i class="icon-chevron-right icon-white"></i>', 'class="btn btn-large btn-primary"');?>
      </div>
      <div class='panel'>
        <h3 id='top_10'><?php echo lang('top_ten_overall');?></h3>
        <table class='table table-condensed'>
          <thead>
            <tr>
              <th><?php echo lang('user_team');?></th>
              <th class='centered'><?php echo lang('points');?></th>
            </tr>
          </thead>
          <tbody>
        <?php $i = 1;?>
        <?php foreach($top_10 as $user_top)
        {
        ?> 
              <tr>
                <td><?php echo $i.". ".$user_top->username; ?></td>
                <td class='centered'><?php echo $user_top->points_overall; ?></td>
              </tr>
         <?php
          $i++;
          }
         ?>
         </tbody>
        </table>
        <?php echo anchor('ranking/overall/', sprintf(lang('see_overall_rankings_after_stage'),$last_stage->stage_id).' <i class="icon-chevron-right icon-white"></i>', 'class="btn btn-large btn-primary"');?>
      </div>
      <?php
      }
      else
      {
      ?>
      
      <?php
      if(!$this->ion_auth->logged_in())
      {
        //user is not logged in, display something
        echo sprintf(lang('home_not_logged_in'), $this->config_model->item('site_name'), anchor('rules', lang('the_rules')));
      }
      else
      {
        //user is logged in, but there is no calculated stage, display something else
        echo "<h3>U heeft nog tot 29 juni om een team samen te stellen!</h3>";
      }
      } 
      ?>


  </div> <!-- end #right-side -->

</div><!-- close .row -->